package leetcode.str;

public class Test58 {
    public static void main(String[] args) {
        String cdefgab = reverseLeftWords("abcdefg", 2);
        System.out.println(cdefgab);
    }
    public static String reverseLeftWords(String s, int n) {
        char[] chars = s.toCharArray();
        int start = 0,end = chars.length-1;
        while (start<=end){
            char t = chars[end];
            chars[end] = chars[start];
            chars[start] = t;
            start++;
            end--;
        }
        start = 0;
        end = chars.length-n-1;
        while (start<=end){
            char t = chars[end];
            chars[end] = chars[start];
            chars[start] = t;
            start++;
            end--;
        }
        start = chars.length-n;
        end = chars.length-1;
        while (start<=end){
            char t = chars[end];
            chars[end] = chars[start];
            chars[start] = t;
            start++;
            end--;
        }
        return new String(chars);
    }
}
